package com.wmm.servlet.student;

import com.wmm.bean.PageBean;
import com.wmm.bean.Student;
import com.wmm.service.StudentService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

@WebServlet(name = "FindStudentByPageServlet",urlPatterns = "/findStudentByPage")
public class FindStudentByPageServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //1. 获取参数
        String currentPage = request.getParameter("currentPage");  //当前页码
        String rows = request.getParameter("rows");                 //每页显示条数

        if(null == currentPage) {
            currentPage = "1";
        }
        if(null == rows) {
            rows = "5";
        }
        //2. 调用service查询
        StudentService service = new StudentService();
        //3. 将PageBean存入session
        HttpSession session = request.getSession();
        PageBean<Student> queryList = service.findStudentByPage(currentPage,rows);

        session.setAttribute("queryList",queryList);
        System.out.println(queryList.toString());
        //4. 转发到show.jsp
        request.getRequestDispatcher("show.jsp").forward(request,response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request, response);
    }
}
